package com.weiyuwqj.server.service.user.impl;

import com.github.pagehelper.PageHelper;
import com.weiyuwqj.api.common.PageList;
import com.weiyuwqj.api.common.Paginator;
import com.weiyuwqj.api.constant.Message;
import com.weiyuwqj.api.exception.CrowdException;
//import com.weiyuwqj.api.hengfeng.model.base.HfResultBean;
//import com.weiyuwqj.api.hengfeng.model.base.HfSuccessDataBean;
//import com.weiyuwqj.api.hengfeng.param.vo.HfCreateAuthVo;
import com.weiyuwqj.api.model.BasUser;
import com.weiyuwqj.api.model.BasUserSecurity;
import com.weiyuwqj.api.model.SysUser;
import com.weiyuwqj.api.model.vo.SecurityVo;
import com.weiyuwqj.api.service.BasUserSecurityService;
import com.weiyuwqj.api.service.BasUserService;
import com.weiyuwqj.api.service.SysLogService;
import com.weiyuwqj.api.service.SysUserService;
import com.weiyuwqj.api.service.module.creater.AbstractLogCreater;
import com.weiyuwqj.server.mapper.BasUserSecurityMapper;
//import com.weiyuwqj.server.pay.MemberApi;
import com.weiyuwqj.server.service.base.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by 姚秀炜 on 2015/12/20.
 */
@Service("userSecurityService")
public class BasUserSecurityServiceImpl extends BaseServiceImpl<BasUserSecurity> implements BasUserSecurityService {
    @Autowired
    BasUserSecurityMapper userSecurityMapper;

//    @Autowired
//    MemberApi memberApi;

    @Autowired
    BasUserService userService;

    @Autowired
    SysUserService sysUserService;

    @Autowired
    private SysLogService logService;


    //后台列表
    @Override
    public PageList getList(Paginator p, Map map) {
        PageHelper.startPage(p.getPageNum(), p.getPageSize());
        List<SecurityVo> list = userSecurityMapper.getList(map);
        return new PageList(list);
    }

    //根据userId查询单条信息
    @Override
    public BasUserSecurity getOneByUserId(Integer userId) {
        return userSecurityMapper.getOneByUserId(userId);
    }

    @Override
    public BasUserSecurity getOneByIdCard(String idCard) {
        return userSecurityMapper.getOneByIdCard(idCard);
    }

    /**
     * 修改实名信息
     * @param realname
     * @param idCard
     * @param userId
     */
    @Override
    public void modifyRealnameByUserId(String realname, String idCard, Integer userId) {
        userSecurityMapper.modifyRealnameByUserId(realname, idCard,userId);
    }
//    /**
//     * 修改实名信息并记录
//     * @param realname 用户真实姓名
//     * @param idCard 身份证号码
//     * @param userId 用户ID
//     * @param logCreater 日志内容
//     * @param successData 用户平台编号
//     */
//    @Override
//    public void modifyRealnameByUserIdAndLog(String realname, String idCard, Integer userId, AbstractLogCreater logCreater, List<HfSuccessDataBean> successData) {
//	    for (HfSuccessDataBean successDataBean : successData) {
//		    logService.save(logCreater.getLog());
//            userSecurityMapper.modifyRealnameByUserId(realname, idCard,userId);
//		    String platcust = successDataBean.getPlatcust();
//		    userService.mobilePlatformId(platcust, userId);
//        }
//
//    }

//    //后台实名
//    @Override
//    public Object doRealname(Integer userId, String realname, String IdCard,Integer type) {
//        BasUserSecurity security=userSecurityMapper.getOneByIdCard(IdCard);
//        if(security!=null){
//            throw new CrowdException("user.bank.idCard.already_exists");
//        }
//
//        HfCreateAuthVo createAuthVo=new HfCreateAuthVo();
//        if(type==3 || type==5){
//            SysUser user=sysUserService.selectByKey(userId);
//            createAuthVo.setMobile(user.getMobile());
//        }else {
//            BasUser user=userService.selectByKey(userId);
//            createAuthVo.setMobile(user.getMobile());
//        }
//        switch (type){
//            case 1:
//                createAuthVo.setBizType("06");
//                break;
//            case 2:
//                createAuthVo.setBizType("06");
//                break;
//            case 3:
//                createAuthVo.setBizType("03");
//                break;
//            case 4:
//                createAuthVo.setBizType("04");
//                break;
//            case 5:
//                createAuthVo.setBizType("05");
//                break;
//            case 6:
//                createAuthVo.setBizType("06");
//                break;
//        }
//        createAuthVo.setCertNo(IdCard);
//        createAuthVo.setRealName(realname);
//        createAuthVo.setUserId(String.valueOf(userId));
//        HfResultBean resultBean = memberApi.createAuth(createAuthVo);// 请求恒丰
//        userSecurityMapper.modifyRealnameByUserId(realname, IdCard, userId);
//        return Message.OK;
//    }

    @Override
    public SecurityVo getUserInfoByUserId(Integer userId) {
        return userSecurityMapper.getUserInfoByUserId(userId);
    }


}
